import { mapState, mapMutations } from 'vuex'
import VueImgInputer from 'vue-img-inputer'
export default {
	name: 'album',
	data() {
		return {
			file: "",
			albumList: [],
		}
	},
	computed: {
		...mapState([
			'token'
		]),
	},
	methods: {
		getAlbumList() {
			this.$axios.get('/album/list')
				.then((res) => {
					if(res.data.status == "1") {
						this.albumList = res.data.result.list;
					}
				})
				.catch((error) => {
					alert("请求异常")
				})
		},
		uploading() {
			/*var that = this;
			var reader = new FileReader();
			reader.readAsDataURL(this.file);
			reader.onload = function(e){
				var param = {readAsDataURL:this.result}
				that.$axios.post('/album/uploading', param)
					.then((res) => {
						if(res.data.status=="1"){
							alert("上传成功");
							that.getAlbumList();
						}
					})
					.catch((error) => {
						console.log(error)
						alert("请求异常")
					})
			}*/
			let param = new FormData();
			param.append('img', this.file);
			let config = {
				headers: {
					'Content-Type': 'multipart/form-data'
				}
			}; 
			this.$axios.post('/album/uploading', param, config)
				.then(res => {
					if(res.data.status=="1"){
						this.getAlbumList();
					}
				})

		},
		del(id) {
			var param = {
				picId: id
			}
			this.$axios.post('/album/del', param)
				.then((res) => {
					if(res.data.status == "1") {
						alert("删除成功");
						this.getAlbumList();
					}
				})
				.catch((error) => {
					console.log(error)
					alert("请求异常")
				})
		}
	},
	components: {
		VueImgInputer
	},
	created() {

		document.title = "相册";
		this.getAlbumList();
	}
}